home *** CD-ROM | disk | FTP | other *** search
- On 16-Mar-98, Declan_Gorman@modusmedia.com wrote:
-
- > My program has a memory bank which consists of 128 blocks of memory,
- > each 256k in size. Each memory block has a name and category and I
- > want to be able to sort the bank by either.
-
- This should do it:
-
- <CUT>
-
- ' Needs sorting string to be located in S_STR$(0) to S_STR$(NUM-1)
- ' ( ... I don't know how to pass arrays to procs...)
-
- _SORT[128,256*1024,BANK_NUMBER,NUMBER_OF_ITEMS_IN_ARRAY,UNUSED_BANK]
-
- Procedure _SORT[NUM,SIZ,BNK,ARR_SIZ,TMP_BNK]
- Shared S_STR$()
-
- Reserve As Work TMP_BNK,SIZ
- Dim CUR(NUM-1),OLD(NUM-1)
-
- 'Add number of item to the end of the string
- For I=0 To NUM-1 : S_STR$(I)=S_STR$(I)+Hex$(I,4) : Next I
- 'ensure that unused items in array will be placed first after sorting
- If ARR_SIZ>NUM
- For I=NUM To ARR_SIZ-1 : S_STR$(I)='' : Next I
- End If
- Sort S_STR$(0)
- 'move sorted items FROM last TO first in array
- For I=0 To NUM-1 : S_STR$(I)=S_STR$(I+ARR_SIZ-NUM) : Next I
-
- 'At this point the first NUM indexes in S_STR$() contains sorted
- 'data - followed by the original position in the array.
-
- For I=0 To NUM-1 : CUR(I)=I : OLD(I)=I : Next I
- 'CUR(ORIGINAL_POS) contains CURRENT_POS
- 'OLD(CURRENT_POS) contains ORIGINAL_POS
-
- For I=0 To NUM-1
- 'OLDI=what index index I had before sorting.
- OLDI=Val(Right$(S_STR$(I),5))
- 'J=Current position of block
- J=CUR(OLDI)
- Print OLDI,J
- S_STR$(I)=Left$(S_STR$(I),Len(S_STR$(I))-5)
- 'swap blocks:
- If I<>J
- Copy Start(BNK)+I*SIZ,Start(BNK)+(I+1)*SIZ To Start(TMP_BNK)
- Copy Start(BNK)+J*SIZ,Start(BNK)+(J+1)*SIZ To Start(BNK)+I*SIZ
- Copy Start(TMP_BNK),Start(TMP_BNK)+SIZ To Start(BNK)+J*SIZ
- Swap CUR(OLD(I)),CUR(OLD(J))
- Swap OLD(I),OLD(J)
- End If
- Next I
- Erase TMP_BNK
- End Proc
-
- <CUT>
-
- Quick tech explanation (hmmm, how it works, eh):
- I use the internal AMOS sort cmd. But before sorting I add the hex number to
- the end of the strings. So if the strings are:
-
- Hi
- There
- !!!
-
- then I add like this:
-
- Hi$0000
- There$0001
- !!!$0002
-
- After sorting (using "Sort") it is:
-
- !!!$0002
- Hi$0000
- There$0001
-
- - and I can use the numbers to move around in the bank.
-
- I reserve a temp bank on the size of one block (that is 256k)
-
- As I do not have 32MB of ram I have not been able to test it with your amount
- of memory. It moves the memory three times. That is: It will move 96MB of
- data! So it'll probably use a small amount of time.
-
- Just write a letter to the list (send a copy to me personally, as I am only
- very seldom at home and therefore incidentally skips some letters in the
- mailinglists) if you have questions.
-
- --
-
- /¯\ __ __ /¯¯¯¯¯\ _ Rune Zedeler
- ________/ /// \\__/ \\\ ---/ \¯-_ Peter Rørdams Vej 19
- \ / //¯| \\/ ||¯\ \\¯¯¯¯¯¯¯¯¯¯¯¯¯¯ ¯-_ 2800 Lyngby
- ) / // | \ ` / || \ \\ Lemmus of Efreet - Denmark
- / / ¯¯¯¯¯\\|\-'/ /¯¯¯¯¯ \\____________ _-¯
- ¯¯¯¯¯\------'/||¯¯| \------'/ /_-¯ rzedeler@post10.tele.dk
- ¯¯¯¯¯¯\-'/ \-'/¯¯¯¯¯¯ ¯ Tel: +45-45871730
- ¯¯ ¯¯
-
-
-